package io.zerous.tile;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;

import java.awt.event.InputEvent;

public class MyGdxGame extends ApplicationAdapter {
	SpriteBatch batch;
	//Texture img;

	Chunk chunk;

	Entity entity;
	World world;
	
	@Override
	public void create () {
		batch = new SpriteBatch();

		Arts.add(new Texture("green.tga"), "Green");

		int[][] a = new int[10][10];
		a[0][0] = 1;

		chunk = new Chunk(a);
        world = new World();

		entity = new Entity(new Vector2(50, 50));

        world.addEntity(entity);
		Gdx.input.setInputProcessor(new InputProcessor() {
            @Override
            public boolean keyDown(int keycode) {
                switch (keycode) {
                    case Input.Keys.D:
                        entity.accel.x = 1;
                        break;

                    case Input.Keys.A:
                        entity.accel.x = -1;
                        break;

                    case Input.Keys.S:
                        entity.accel.y = -1;
                        break;

                    case Input.Keys.W:
                        entity.accel.y = 1;
                }
                return false;
            }

            @Override
            public boolean keyUp(int keycode) {
                switch (keycode) {
                    case Input.Keys.D:
                    case Input.Keys.A:
                        entity.accel.x = 0;
                        break;

                    case Input.Keys.W:
                    case Input.Keys.S:
                        entity.accel.y = 0;
                        break;
                }
                return false;
            }

            @Override
            public boolean keyTyped(char character) {
                return false;
            }

            @Override
            public boolean touchDown(int screenX, int screenY, int pointer, int button) {
                return false;
            }

            @Override
            public boolean touchUp(int screenX, int screenY, int pointer, int button) {
                return false;
            }

            @Override
            public boolean touchDragged(int screenX, int screenY, int pointer) {
                return false;
            }

            @Override
            public boolean mouseMoved(int screenX, int screenY) {
                return false;
            }

            @Override
            public boolean scrolled(int amount) {
                return false;
            }
        });

	}

	@Override
	public void render () {
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

		world.update();

		batch.begin();
		entity.draw(batch);
		chunk.draw(batch);
		batch.end();
	}
	
	@Override
	public void dispose () {
		batch.dispose();
	}
}
